<template>
  <div class="thank-you-page">
    <div class="background-animation">
      <div class="floating-hearts">
        <span v-for="i in 20" :key="i" class="heart" :style="getHeartStyle(i)">❤️</span>
      </div>
    </div>
    
    <div class="content">
      <div class="success-icon">
        <el-icon><CircleCheckFilled /></el-icon>
      </div>
      
      <h1 class="title">🎉 评价提交成功！</h1>
      <p class="subtitle">感谢您的反馈，让我们共同打造更好的校园互助平台</p>
      
      <div class="stats">
        <div class="stat-item">
          <div class="stat-number">{{ stats.totalReviews }}</div>
          <div class="stat-label">累计评价</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ stats.avgRating }}</div>
          <div class="stat-label">平均评分</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ stats.satisfactionRate }}%</div>
          <div class="stat-label">满意度</div>
        </div>
      </div>
      
      <div class="danmaku-container">
        <div class="danmaku-track" v-for="track in 5" :key="track">
          <div 
            v-for="danmaku in getDanmakuByTrack(track)" 
            :key="danmaku.id"
            class="danmaku"
            :style="getDanmakuStyle(danmaku)"
          >
            {{ danmaku.text }}
          </div>
        </div>
      </div>
      
      <div class="actions">
        <AnimatedButton 
          type="primary" 
          size="large"
          @click="goToHome"
        >
          返回首页
        </AnimatedButton>
        <AnimatedButton 
          type="success" 
          size="large"
          @click="shareExperience"
        >
          分享体验
        </AnimatedButton>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { CircleCheckFilled } from '@element-plus/icons-vue'
import AnimatedButton from './components/AnimatedButton.vue'

/**
 * 弹幕感谢页面组件
 * @description 评价提交成功后的感谢展示页面，包含弹幕效果
 */
const router = useRouter()

// 统计数据
const stats = reactive({
  totalReviews: 15420,
  avgRating: 4.8,
  satisfactionRate: 96.5
})

// 弹幕数据
const danmakuList = ref([
  { id: 1, text: '感谢您的评价！', track: 1, color: '#ff6b6b' },
  { id: 2, text: '服务很满意！', track: 2, color: '#4ecdc4' },
  { id: 3, text: '下次还找你！', track: 3, color: '#45b7d1' },
  { id: 4, text: '态度超好！', track: 4, color: '#96ceb4' },
  { id: 5, text: '准时送达！', track: 5, color: '#feca57' },
  { id: 6, text: '包装完好！', track: 1, color: '#ff9ff3' },
  { id: 7, text: '性价比高！', track: 2, color: '#54a0ff' },
  { id: 8, text: '超出预期！', track: 3, color: '#5f27cd' },
  { id: 9, text: '值得推荐！', track: 4, color: '#00d2d3' },
  { id: 10, text: '校园互助真棒！', track: 5, color: '#ff9f43' }
])

let animationFrame = null

/**
 * 获取爱心样式
 * @param {number} index - 爱心索引
 * @returns {Object} 样式对象
 */
const getHeartStyle = (index) => {
  const delay = Math.random() * 5
  const duration = 3 + Math.random() * 2
  const left = Math.random() * 100
  
  return {
    left: `${left}%`,
    animationDelay: `${delay}s`,
    animationDuration: `${duration}s`
  }
}

/**
 * 获取指定轨道的弹幕
 * @param {number} track - 轨道号
 * @returns {Array} 弹幕列表
 */
const getDanmakuByTrack = (track) => {
  return danmakuList.value.filter(d => d.track === track)
}

/**
 * 获取弹幕样式
 * @param {Object} danmaku - 弹幕对象
 * @returns {Object} 样式对象
 */
const getDanmakuStyle = (danmaku) => {
  const delay = Math.random() * 10
  return {
    color: danmaku.color,
    animationDelay: `${delay}s`
  }
}

/**
 * 返回首页
 */
const goToHome = () => {
  router.push('/campus-entrust/list')
}

/**
 * 分享体验
 */
const shareExperience = () => {
  ElMessage.success('分享功能开发中...')
}

/**
 * 启动动画
 */
const startAnimation = () => {
  const animate = () => {
    // 更新统计数据动画
    stats.totalReviews += Math.floor(Math.random() * 3)
    stats.avgRating = Math.min(5, stats.avgRating + (Math.random() - 0.5) * 0.1)
    stats.satisfactionRate = Math.min(100, stats.satisfactionRate + (Math.random() - 0.5) * 0.5)
    
    animationFrame = requestAnimationFrame(animate)
  }
  animate()
}

// 生命周期钩子
onMounted(() => {
  startAnimation()
})

onUnmounted(() => {
  if (animationFrame) {
    cancelAnimationFrame(animationFrame)
  }
})
</script>

<style scoped>
.thank-you-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.background-animation {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.floating-hearts {
  position: relative;
  width: 100%;
  height: 100%;
}

.heart {
  position: absolute;
  font-size: 24px;
  animation: float-up 5s linear infinite;
  opacity: 0.6;
}

@keyframes float-up {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(-100px) rotate(360deg);
    opacity: 0;
  }
}

.content {
  text-align: center;
  color: white;
  z-index: 1;
  position: relative;
  max-width: 600px;
  padding: 40px 20px;
}

.success-icon {
  font-size: 80px;
  color: #4ecdc4;
  margin-bottom: 20px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-20px);
  }
  60% {
    transform: translateY(-10px);
  }
}

.title {
  font-size: 36px;
  font-weight: 700;
  margin: 0 0 16px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
  font-size: 18px;
  opacity: 0.9;
  margin: 0 0 40px 0;
  line-height: 1.5;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 40px;
}

.stat-item {
  text-align: center;
}

.stat-number {
  font-size: 32px;
  font-weight: 700;
  color: #ffd700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  opacity: 0.8;
}

.danmaku-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

.danmaku-track {
  position: absolute;
  width: 100%;
  height: 40px;
}

.danmaku-track:nth-child(1) { top: 10%; }
.danmaku-track:nth-child(2) { top: 25%; }
.danmaku-track:nth-child(3) { top: 40%; }
.danmaku-track:nth-child(4) { top: 55%; }
.danmaku-track:nth-child(5) { top: 70%; }

.danmaku {
  position: absolute;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  animation: danmaku-move 15s linear infinite;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes danmaku-move {
  0% {
    transform: translateX(100vw);
  }
  100% {
    transform: translateX(-100%);
  }
}

.actions {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-top: 40px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .content {
    padding: 20px;
  }
  
  .title {
    font-size: 28px;
  }
  
  .subtitle {
    font-size: 16px;
  }
  
  .stats {
    flex-direction: column;
    gap: 20px;
  }
  
  .actions {
    flex-direction: column;
    align-items: center;
  }
  
  .danmaku {
    font-size: 14px;
  }
}
</style> 